<?php defined('In33hao') or exit('Access Invalid!');?>
<div class="page">
    <div class="fixed-bar">
        <div class="item-title"><a class="back" href="index.php?act=agent&op=index" title="返回代理列表"><i class="fa fa-arrow-circle-o-left"></i></a>
            <div class="subject">
                <h3>商圈代理 - <?php echo $lang['nc_edit'];?></h3>
                <h5>商圈代理相关设置和管理</h5>
            </div>
        </div>
    </div>
    <form id="agent_form" enctype="multipart/form-data" method="post">
        <input type="hidden" name="form_submit" value="ok" />
        <input type="hidden" name="province_id" id="_area_1">
        <input type="hidden" name="city_id" id="_area_2">
        <input type="hidden" name="area_id" id="_area_3">
        <input type="hidden" name="id" value="<?php echo $output['agent']['id']; ?>">
        <div class="ncap-form-default">
            <dl class="row">
                <dt class="tit">
                    <label for="store_name"><em>*</em>代理名称</label>
                </dt>
                <dd class="opt">
                    <input type="text" id="title" name="title" class="input-txt" value="<?php echo $output['agent']['title']; ?>"/>
                    <span class="err"></span>
                    <p class="notic"></p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label for="type"><em>*</em>代理类别</label>
                </dt>
                <dd class="opt">
                    <input type="radio" value="2" <?php if($output['agent']['type'] == 2){?>checked <?php }?> name="type" id="type1"><label for="type1">市代</label>
                    <input type="radio" value="3" <?php if($output['agent']['type'] == 3){?>checked <?php }?> name="type" id="type2"><label for="type2">镇代</label>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label for="region"><em>*</em>所属地区</label>
                </dt>
                <dd class="opt">
                <div class="area-region-select"><input id="region" name="region" type="hidden" value="<?php echo $output['agent']['area_info']?>" >
                    <span class="err"></span></div>
                </dd>
            </dl>
            <div class="bot"><a href="JavaScript:void(0);" class="ncap-btn-big ncap-btn-green" id="submitBtn"><?php echo $lang['nc_submit'];?></a></div>
        </div>
    </form>
</div>
<script>
    $(function(){

        $("#region").nc_region();

//按钮先执行验证再提交表单
        $("#submitBtn").click(function(){
            if($("#agent_form").valid()){
                $("#agent_form").submit();
            } else {
            }
        });

//表单验证
        $('#agent_form').validate({
            errorPlacement: function(error, element){
                var error_td = element.parent('dd').children('span.err');
                error_td.append(error);
            },
            rules : {
                title : {
                    required : true,
                    remote   : {
                        url :'index.php?act=agent&op=check_title',
                        type:'get',
                        data:{
                            title : function(){
                                return $('#title').val();
                            },
                            type : function(){
                                return $("input[name='type']:checked").val();
                            },
                            id : function(){
                                return $("input[name='id']").val();
                            }
                        }
                    }
                },
                region : {
                    checklast: true
                },
                member_name: {
                    required : true,
                    minlength : 3,
                    maxlength : 15,
                    remote   : {
                        url : 'index.php?act=ownshop&op=check_member_name',
                        type: 'get',
                        data:{
                            member_name : function(){
                                return $('#member_name').val();
                            }
                        }
                    }
                },
                member_passwd : {
                    required : true,
                    minlength: 6
                },
                member_points : {
                    required : true,
                    digits:true
                },
            },
            messages : {
                title : {
                    required : '<i class="fa fa-exclamation-circle"></i>代理名称不能为空',
                    remote   : '<i class="fa fa-exclamation-circle"></i>该代理名称已存在'
                },
                member_name: {
                    required : '<i class="fa fa-exclamation-circle"></i>请输入会员账号',
                    minlength: '<i class="fa fa-exclamation-circle"></i>会员账号最短为3位',
                    maxlength: '<i class="fa fa-exclamation-circle"></i>会员账号最长为15位',
                    remote   : '<i class="fa fa-exclamation-circle"></i>此名称已被其它店铺会员占用，请重新输入'
                },
                member_passwd : {
                    required : '<i class="fa fa-exclamation-circle"></i>请输入登录密码',
                    minlength: '<i class="fa fa-exclamation-circle"></i>登录密码长度不能小于6'
                },
                member_points : {
                    required : '<i class="fa fa-exclamation-circle"></i>请输入积分值',
                    digits: '<i class="fa fa-exclamation-circle"></i>积分必须输入整数'
                }
            }
        });

    });
</script>
